In [1]:
import requests

1 Make a request from the Forecast.io API for where you were born (or lived, or want to visit!)

Tip: Once you've imported the JSON into a variable, check the timezone's name to make sure it seems like it got the right part of the world! Tip 2: How is north vs. south and east vs. west latitude/longitude represented? Is it the normal North/South/East/West?


In [21]:
#https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/12.971599,77.594563')
data = response.json()
#print(data)
#print(data.keys())
print("Bangalore is in", data['timezone'], "timezone")
timezone_find = data.keys()
#find representation


Bangalore is in Asia/Kolkata timezone

In [ ]:

2. What's the current wind speed? How much warmer does it feel than it actually is?


In [35]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
#print(data.keys())
print("The current windspeed at New York is", data['currently']['windSpeed'])
#print(data['currently']) - find how much warmer


The current windspeed at New York is 6.31
{'summary': 'Clear', 'apparentTemperature': 64.21, 'humidity': 0.59, 'ozone': 362.48, 'dewPoint': 49.77, 'precipProbability': 0, 'cloudCover': 0.06, 'windSpeed': 6.31, 'precipIntensity': 0, 'temperature': 64.21, 'pressure': 1003.16, 'windBearing': 269, 'time': 1465390846, 'icon': 'clear-day', 'visibility': 10}

3. Moon Visible in New York

The first daily forecast is the forecast for today. For the place you decided on up above, how much of the moon is currently visible?


In [58]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
#print(data.keys())
#print(data['daily']['data'])

now_moon = data['daily']['data']
for i in now_moon:
    print("The visibility of moon today in New York is", i['moonPhase'])


The visibility of moon today in New York is 0.13

4. What's the difference between the high and low temperatures for today?


In [66]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
TemMax = data['daily']['data']
for i in TemMax:
    tem_diff = i['temperatureMax'] - i['temperatureMin']
    print("The temparature difference for today approximately is", round(tem_diff))


The temparature difference for today approximately is 9

5. Next Week's Prediction

Loop through the daily forecast, printing out the next week's worth of predictions. I'd like to know the high temperature for each day, and whether it's hot, warm, or cold, based on what temperatures you think are hot, warm or cold.


In [88]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941')
data = response.json()
temp = data['daily']['data']
#print(temp)
count = 0
for i in temp:
    count = count+1
    print("The high temperature for the day", count, "is", i['temperatureMax'], "and the low temperature is", i['temperatureMin'])
    if float(i['temperatureMin']) < 40:
        print("it's a cold weather")
    elif (float(i['temperatureMin']) > 40) & (float(i['temperatureMin']) < 60):
        print("It's a warm day!")
    else:
        print("It's very hot weather")


The high temperature for the day 1 is 66.3 and the low temperature is 56.93
It's a warm day!
The high temperature for the day 2 is 74.47 and the low temperature is 53.1
It's a warm day!
The high temperature for the day 3 is 75.89 and the low temperature is 56.6
It's a warm day!
The high temperature for the day 4 is 75.17 and the low temperature is 59.3
It's a warm day!
The high temperature for the day 5 is 79.85 and the low temperature is 65.16
It's very hot weather
The high temperature for the day 6 is 68.26 and the low temperature is 60.65
It's very hot weather
The high temperature for the day 7 is 74.71 and the low temperature is 62.07
It's very hot weather
The high temperature for the day 8 is 76.22 and the low temperature is 61.69
It's very hot weather

6.Weather in Florida

What's the weather looking like for the rest of today in Miami, Florida? I'd like to know the temperature for every hour, and if it's going to have cloud cover of more than 0.5 say "{temperature} and cloudy" instead of just the temperature.


In [104]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/25.761680,-80.191790, 2016-06-09T12:01:00-0400')
data = response.json()
#print(data['hourly']['data'])
Tem = data['hourly']['data']
count = 0
for i in Tem:
    count = count +1
    print("The temperature in Miami, Florida on 9th June in the", count, "hour is", i['temperature'])
    if float(i['cloudCover']) > 0.5:
        print("and is cloudy")


The temperature in Miami, Florida on 9th June in the 1 hour is 77.52
and is cloudy
The temperature in Miami, Florida on 9th June in the 2 hour is 77.49
and is cloudy
The temperature in Miami, Florida on 9th June in the 3 hour is 77.69
and is cloudy
The temperature in Miami, Florida on 9th June in the 4 hour is 77.69
and is cloudy
The temperature in Miami, Florida on 9th June in the 5 hour is 77.83
and is cloudy
The temperature in Miami, Florida on 9th June in the 6 hour is 78.02
and is cloudy
The temperature in Miami, Florida on 9th June in the 7 hour is 77.77
and is cloudy
The temperature in Miami, Florida on 9th June in the 8 hour is 77.99
and is cloudy
The temperature in Miami, Florida on 9th June in the 9 hour is 78.94
and is cloudy
The temperature in Miami, Florida on 9th June in the 10 hour is 80.37
and is cloudy
The temperature in Miami, Florida on 9th June in the 11 hour is 82.11
and is cloudy
The temperature in Miami, Florida on 9th June in the 12 hour is 83.76
and is cloudy
The temperature in Miami, Florida on 9th June in the 13 hour is 84.98
and is cloudy
The temperature in Miami, Florida on 9th June in the 14 hour is 85.84
and is cloudy
The temperature in Miami, Florida on 9th June in the 15 hour is 86.27
and is cloudy
The temperature in Miami, Florida on 9th June in the 16 hour is 85.79
and is cloudy
The temperature in Miami, Florida on 9th June in the 17 hour is 85.37
and is cloudy
The temperature in Miami, Florida on 9th June in the 18 hour is 84.97
and is cloudy
The temperature in Miami, Florida on 9th June in the 19 hour is 84.2
and is cloudy
The temperature in Miami, Florida on 9th June in the 20 hour is 83.44
and is cloudy
The temperature in Miami, Florida on 9th June in the 21 hour is 82.71
and is cloudy
The temperature in Miami, Florida on 9th June in the 22 hour is 82.04
and is cloudy
The temperature in Miami, Florida on 9th June in the 23 hour is 81.28
and is cloudy
The temperature in Miami, Florida on 9th June in the 24 hour is 80.47
and is cloudy

7. Temperature in Central Park

What was the temperature in Central Park on Christmas Day, 1980? How about 1990? 2000?


In [113]:
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 1980-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 1980 was", Temp)

response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 1990-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 1990 was", Temp)

response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 2000-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 2000 was", Temp)


The temperature in Central Park, NY on the Christmas Day of 1980 was 3.57
The temperature in Central Park, NY on the Christmas Day of 1990 was 30.28
The temperature in Central Park, NY on the Christmas Day of 2000 was 20.68

In [ ]: